/*
 * RTSAI - Real-Time Strategy engine for AI research
 * Copyright(C) 2006 DIMAp-UFRN, licensed under LGPL
 *
 * RTSAI "Capture the flag" application
 */

#include "rtsai.h"
#include "Common.h"
#include "GameView.h"
#include "Log.h"

const Vector3D player_colors[] = {
    Vector3D(0.7,0.7,0.5),     // attackers color
    Vector3D(0.5,0.7,0.7)      // seeker color
};

const Vector3D obst_color (0.8f, 0.6f, 0.4f);

void view_update(void)
{
    Game& game = Game :: getInstance();

    // draw players teams
    Pool < Player > players = game.get_players();
    foreach ( pl, players )
    {
        Pool < Unit > units = (*pl).get_units();
        int id = (*pl).get_id();
        foreach ( u, units )
        {
            GameView::drawVehicle ((*u), player_colors [ id ]);
        }
    }

    // draw obstacles
    ObjectList *objects = game.get_objs();
    for ( ObjectList::iterator obj = objects->begin() ; obj != objects->end() ; ++obj )
    {
        // TODO this a dependency of OpenSteer library
        GameObject *gobj = dynamic_cast < GameObject* > ( *obj );
        GameView::drawObject ((*gobj), obst_color);
    }
}


int main(int argc, char **argv) {
    // setting debug output messages
    Logger :: set_level ( Logger :: DEBUG );

    LOG << "=== Capture-the-flag ===" << std::endl;
    if (argc > 1) {
        Game :: getInstance().init ( argv[1] );
        GameView :: init ( argc, argv, view_update );
        GameView :: start_loop();
    }
    else {
        LOG << "Usage: " << argv[0] << " <game_description_file.lua>" << std::endl;
        exit(1);
    }
}
